﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WoChu.RfClient.Common;
using WoChu.RfClient.Entity;
using WoChu.CF.BaseFrame.Util;

namespace WoChu.RfClient.Duty
{
    public partial class FrmDutyQuery : BaseForm
    {
        private string userID = string.Empty;

        public FrmDutyQuery()
        {
            InitializeComponent();
        }

        // LOAD
        private void FrmDutyQuery_Load(object sender, EventArgs e)
        {
            this.txtUserID.Text = LoginBean.Instance.UserID;
            this.txtUserID.Focus();
        }

        // 扫描工号
        private void txtUserID_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (!this.txtUserID.Text.Trim().Equals(string.Empty))
                {
                    try
                    {
                        bool isExists = DutyUIRule.NewInstance.IsUserExists(LoginBean.Instance.ShopID, this.txtUserID.Text);
                        if (!isExists)
                        {
                            MessageBox.Show("当前用户不存在！");
                            this.txtUserID.Focus();
                        }

                        userID = this.txtUserID.Text;
                        this.dateTimePicker1.Focus();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }

        // 查询
        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                if (userID.Equals(string.Empty) && !this.txtUserID.Text.Equals(LoginBean.Instance.UserID))
                {
                    MessageBox.Show("请输入正确的工号！");
                    this.txtUserID.Focus();
                    return;
                }

                List<ShopLocGuideListInfo> dutyInfo = DutyUIRule.NewInstance.DutyQuery(LoginBean.Instance.ShopID, this.txtUserID.Text, this.dateTimePicker1.Text);
                this.grdDtl.DataSource = this.bindingSource1;
                this.bindingSource1.DataSource = dutyInfo;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void FrmDutyQuery_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                if (MessageBoxEx.Question("确定退出吗？") == DialogResult.Yes)
                {
                    FrmDutyMain frmDutyMain = new FrmDutyMain();
                    frmDutyMain.Show();
                    this.Close();
                    this.Dispose();
                }
            }
        }
    }
}